package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 推送类型:1申请,2主动
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum UsePushOperateEnum {

  /** 推送 */
  PUSH(1, "推送"),
  CANCEL_PUSH(2, "取消推送"),
  REFUSE(3, "驳回"),
  ;
  private Integer code;
  private String desc;

  public static UsePushOperateEnum convert(Integer type) {
    return Arrays.stream(values())
        .filter(x -> x.code.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到推送状态：" + type));
  }

  @JsonCreator
  public static UsePushOperateEnum getValue(Integer type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.code, type)).findAny().orElse(null);
  }
}
